import java.util.Vector;

/* Todo:
	*temporary hitpoints
	*conditions (separate class required)
	*intelligent power selection
	*a constructor that takes a level and role and populates accordingly
	*copy constructor
	*healing
*/

/**
* Combatant is the Object used to describe players and monsters.  These are
* then contained in Party objects (which are, in turn, contained by Encounter
* objects)
*/
public class Combatant
{
	private String sName;
	private int iAC;
	private int iReflex;
	private int iWill;
	private int iFort;
	private int iHP;
	private int iMaxDmgHP;
	private int iHealingSurges;
	private int iInitiative;
	private Party inParty;
	private AI aAI;
	private Vector<Action> vAtWills;
	private Vector<Action> vEncounters;
	private Vector<Action> vAvailableEncounters;
	private Vector<Action> vDailies;
	private Vector<Action> vAvailableDailies;
	// add at-will, encounter, and daily vectors here
	Combatant(String sMyName, int iMyAC, int iMyReflex, int iMyWill, int iMyFort, int iMyHP)
	{
		sName = sMyName;
		iAC = iMyAC;
		iReflex = iMyReflex;
		iWill = iMyWill;
		iFort = iMyFort;
		iHP = iMyHP;
		iMaxDmgHP = iMyHP;
		iHealingSurges = 6;  // just a decent number
		iInitiative = 3; // again, simple number
		vAtWills = new Vector<Action>();
		vEncounters = new Vector<Action>();
		vAvailableEncounters = new Vector<Action>();
		vDailies = new Vector<Action>();
		vAvailableDailies = new Vector<Action>();
		aAI = new DefaultAI();
	}
	public String getName()
	{
		return sName;
	}
	public int getAC()
	{
		return iAC;
	}
	public int getReflex()
	{
		return iReflex;
	}
	public int getWill()
	{
		return iWill;
	}
	public int getFort()
	{
		return iFort;
	}
	public Party getParty()
	{
		return inParty;
	}
	public int getInit()
	{
		return iInitiative;
	}
	public int getHP()
	{
		return iHP;
	}
	public void setParty(Party myParty)
	{
		inParty = myParty;
	}
	public void setHSurges(int iSurges)
	{
		iHealingSurges = iSurges;
	}
	public void setInit(int iNewInit)
	{
		iInitiative = iNewInit;
	}
	public void addAtWill(Action newAction)
	{
		vAtWills.add(newAction);
	}
	public void addEncntr(Action newAction)
	{
		vEncounters.add(newAction);
		vAvailableEncounters.add(newAction);
	}
	public void addDaily(Action newAction)
	{
		vDailies.add(newAction);
		vAvailableDailies.add(newAction);
	}
	public void takeDamage(int iDamage)
	{
		iHP -= iDamage;
		String sMessage = getName() +" takes "+ iDamage +" damage. ";
		sMessage += iHP +" hitpoints left";
		if (iHP <= 0)
		{
			if(inParty != null) // just in case party hasnt been set
			{
				inParty.delUnit(this);
			}
			sMessage += "\n"+sName + " is dead.";
		}
		getParty().getEncounter().printLog(sMessage);
	}
	public Action getRAtwill()
	{
		if(vAtWills.size() >=1)
		{
			// atm we just use the first at-will
			return vAtWills.elementAt(0);
		}
		else
		{
			return null;
		}
	}
	public void doTurn(Encounter eEncounter)
	{
		// to do this right, we really need a vector of attacks
		if (iHP > 0)
		{
			aAI.doTurn(eEncounter, getParty(), this);
		}
		/*if(vAtWills.size() >=1)
		{
			// atm we just use the first at-will
			Action aAttack = vAtWills.elementAt(0);
			aAttack.doAction(Victim);
		}*/
	}
}
